﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using Microsoft.VisualStudio.TemplateWizard;
using System.Windows.Forms;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.OLE.Interop;
using Microsoft.VisualStudio.SharePoint;

namespace EntiyInstanceSiteLib
{
   // webaprt types
    public enum WebpartTypeCodes
    {
        BusinessDataItem,
        BusinessDataRelatedList,
        RelatedDocumentList,
        BusinessDataActions,
        BusinessDataList,
        SharetheInstanceSiteLink,
        RelatedDocumentAction,
        RelatedDocumentAction2,
        Others

    }    

     public class WebPartStandardDefinition
    {
        public string webpartType;
        public string schema;

    }

    // template wizard class
    public class MyWizard : IWizard
     {
         String InstanceSiteVSTemplateWizardExe = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\InstanceSiteVSTemplateWizard.exe";
         String updateTemplateNameExe = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\UpdateTemplateName.exe";
         String fileName = Path.Combine(Path.GetTempPath(), "InstanceSiteEntityDetails.txt");
        
         WebPartStandardDefinition[] webPartStandarddefinition = new WebPartStandardDefinition[11];
         WebPartDefinition[] webPartDefinition = new WebPartDefinition[30];
         
         string SharePointUrl;
         bool IsSandboxed = false, isUpdateTemplateName=false;
         string startBlock = "__BEGIN123xyz";
         string endBlock = "__END123xyz";
         string templateName;   
         string entityselectedfieldsproperty, entitydeselectedfieldsproperty;
         string entityfieldsproperty1, entityfieldsproperty2, entityfieldsproperty3, entityfieldsproperty4;
        

         string itemEntityselectedfieldsproperty, itemEntitydeselectedfieldsproperty;
         string itemEntityfieldsproperty1, itemEntityfieldsproperty2, itemEntityfieldsproperty3, itemEntityfieldsproperty4;

         string docEntityselectedfieldsproperty, docEntitydeselectedfieldsproperty;
         string docEntityfieldsproperty1, docEntityfieldsproperty2, docEntityfieldsproperty3, docEntityfieldsproperty4;

         int i;
         String[] str;
       

        
         private struct Constants
         {
             internal const string BusinessDataItemBuilder = "BusinessDataItemBuilder";
             internal const string BDWPItem = "BDWP Item";
             internal const string BDWPRelatedItems = "BDWP Related Items";
             internal const string BDWPRow = "BDWP Row";

             internal const string RelatedDocAction = "RelatedDocAction";
             internal const string RelatedActionWebpartName = "ShowRelatedActions";
             internal const string SharetheSiteLink = "Share the instance site Link";

         }
         public void BeforeOpeningFile(EnvDTE.ProjectItem projectItem)
         {

         }

        // updating the template propery in BDC model with the project name
        // Updating the url and sandboxsoluton=false for proejct proeprties

         public void ProjectFinishedGenerating(EnvDTE.Project project)
         {
             Microsoft.VisualStudio.OLE.Interop.IServiceProvider dTE = project.DTE as Microsoft.VisualStudio.OLE.Interop.IServiceProvider;
             ServiceProvider provider2 = new ServiceProvider(dTE);
             ISharePointProject project2 = (provider2.GetService(typeof(ISharePointProjectService)) as ISharePointProjectService).Convert<EnvDTE.Project, ISharePointProject>(project);

             if (isUpdateTemplateName)
             {
                 String args;
                 args = SharePointUrl + " " + webPartDefinition[0].entityNameproperty + " " + webPartDefinition[0].entityNameSpaceproperty;
                 args += " " + project.Name + " ";
                 Process process = Process.Start(updateTemplateNameExe, args);
             }

             if (project2 != null)
             {
                 string str = Path.GetDirectoryName(project2.FullPath) + @"\";
                 project2.SiteUrl = new Uri(SharePointUrl);
                 project2.IsSandboxedSolution = IsSandboxed;

             }
             project2.Synchronize();
         }

         public void ProjectItemFinishedGenerating(EnvDTE.ProjectItem projectItem)
         {

         }

         public void RunFinished()
         {

         }

         // this method will show the Wizards for the project templates 

         public void RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams)
         {
             string connectionString = null;
             string webpartsData = null;
             string sitedefid;
             string templateName;   
             string webPartTypes;

             SharepointForm form = new SharepointForm();
             form.ShowDialog();
             SharePointUrl = @form.sharepointURL;

             String args;
             args = fileName + "  " + SharePointUrl;
             Process process = Process.Start(InstanceSiteVSTemplateWizardExe, args);
             process.WaitForExit();

             str = File.ReadAllLines(fileName);

             i = 0;
             sitedefid = str[i++].ToString();             
             replacementsDictionary.Add("$sitedefid$", sitedefid);
             templateName = str[i++].ToString();
             replacementsDictionary.Add("$templateName$", templateName);
             if (templateName.CompareTo("none") == 0)
                 isUpdateTemplateName = true;

             getStandardDefinition();

             int j = 0;

             /* depending on webpart type, we are reading corresponding information from the file */
             while (true)
             {
                 webPartTypes = str[i++];
                 if (webPartTypes == null || webPartTypes.Length == 0)
                     break;
                 webPartDefinition[j] = new WebPartDefinition();
                 if (webPartTypes.CompareTo(WebpartTypeCodes.BusinessDataActions.ToString()) == 0)
                 {
                     webPartDefinition[j].entityNameproperty = str[i++].ToString();
                     webPartDefinition[j].entityNameSpaceproperty = str[i++].ToString();
                     webPartDefinition[j].lobSystempInstanceroperty = str[i++].ToString();
                     webPartDefinition[j].webpartType = WebpartTypeCodes.BusinessDataActions;
                     webPartDefinition[j].WebPartName = Constants.RelatedActionWebpartName;
                     webPartDefinition[j].connectionID = "Connection" + (j + 1).ToString();
                     webPartDefinition[j].providerID = Constants.BusinessDataItemBuilder;
                     webPartDefinition[j].consumerConnectionPointID = Constants.BDWPItem;
                     webPartDefinition[j].providerConnectionPointID = Constants.BDWPItem;
                     webPartDefinition[j].webpartOrder = j;
                     webPartDefinition[j].fullSchema = webPartStandarddefinition[3].schema;
                     j++;
                 }
                 else if (webPartTypes.CompareTo(WebpartTypeCodes.BusinessDataItem.ToString()) == 0)
                 {
                     webPartDefinition[j].entityNameproperty = str[i++].ToString();
                     webPartDefinition[j].entityNameSpaceproperty = str[i++].ToString();
                     webPartDefinition[j].lobSystempInstanceroperty = str[i++].ToString();
                     webPartDefinition[j].specificFinderproperty = str[i++].ToString();
                     webPartDefinition[j].entityfieldsproperty1 = getBlockProperty();
                     webPartDefinition[j].entityfieldsproperty2 = getBlockProperty();
                     webPartDefinition[j].entityfieldsproperty3 = getBlockProperty();
                     webPartDefinition[j].entityfieldsproperty4 = getBlockProperty();
                     webPartDefinition[j].webpartType = WebpartTypeCodes.BusinessDataItem;
                     webPartDefinition[j].WebPartName = "Show" + webPartDefinition[j].entityNameproperty + "Details";
                     webPartDefinition[j].connectionID = "Connection" + (j + 1).ToString();
                     webPartDefinition[j].providerID = Constants.BusinessDataItemBuilder;
                     webPartDefinition[j].consumerConnectionPointID = Constants.BDWPItem;
                     webPartDefinition[j].providerConnectionPointID = Constants.BDWPItem;
                     webPartDefinition[j].webpartOrder = j;
                     webPartDefinition[j].fullSchema = webPartStandarddefinition[1].schema;
                     j++;
                     webPartDefinition[j] = new WebPartDefinition();
                     webPartDefinition[j].entityNameproperty = webPartDefinition[j - 1].entityNameproperty;
                     webPartDefinition[j].entityNameSpaceproperty = webPartDefinition[j - 1].entityNameSpaceproperty;
                     webPartDefinition[j].lobSystempInstanceroperty = webPartDefinition[j - 1].lobSystempInstanceroperty;
                     webPartDefinition[j].webpartType = WebpartTypeCodes.SharetheInstanceSiteLink;
                     webPartDefinition[j].WebPartName = Constants.SharetheSiteLink;
                     webPartDefinition[j].connectionID = "Connection" + (j + 1).ToString();
                     webPartDefinition[j].providerID = Constants.BusinessDataItemBuilder;
                     webPartDefinition[j].consumerConnectionPointID = Constants.BDWPItem;
                     webPartDefinition[j].providerConnectionPointID = Constants.BDWPItem;
                     webPartDefinition[j].webpartOrder = j;
                     webPartDefinition[j].fullSchema = webPartStandarddefinition[4].schema;
                     j++;
                 }
                 else if (webPartTypes.CompareTo(WebpartTypeCodes.BusinessDataRelatedList.ToString()) == 0)
                 {
                     webPartDefinition[j].entityNameproperty = str[i++].ToString();
                     webPartDefinition[j].entityNameSpaceproperty = str[i++].ToString();
                     webPartDefinition[j].lobSystempInstanceroperty = str[i++].ToString();
                     webPartDefinition[j].associatedEntityName = str[i++].ToString();
                     webPartDefinition[j].providerConnectionPointID = str[i++].ToString();
                     webPartDefinition[j].entityfieldsproperty1 = getBlockProperty();
                     webPartDefinition[j].entityfieldsproperty2 = getBlockProperty();
                     webPartDefinition[j].entityfieldsproperty3 = getBlockProperty();
                     webPartDefinition[j].entityfieldsproperty4 = getBlockProperty();
                     webPartDefinition[j].webpartType = WebpartTypeCodes.BusinessDataRelatedList;
                     webPartDefinition[j].WebPartName = "Show" + webPartDefinition[j].entityNameproperty + "List";
                     webPartDefinition[j].connectionID = "Connection" + (j + 1).ToString();
                     if (webPartDefinition[j].associatedEntityName.CompareTo(webPartDefinition[0].entityNameproperty) == 0)
                         webPartDefinition[j].providerID = Constants.BusinessDataItemBuilder;
                     else
                         webPartDefinition[j].providerID = "Show" + webPartDefinition[j].associatedEntityName + "List";
                     webPartDefinition[j].consumerConnectionPointID = Constants.BDWPRelatedItems;
                     //webPartDefinition[j].providerConnectionPointID = Constants.BDWPItem;
                     webPartDefinition[j].webpartOrder = j;
                     webPartDefinition[j].fullSchema = webPartStandarddefinition[2].schema;
                     j++;

                 }
                 else if (webPartTypes.CompareTo(WebpartTypeCodes.RelatedDocumentList.ToString()) == 0)
                 {
                     webPartDefinition[j].entityNameproperty = str[i++].ToString();
                     webPartDefinition[j].entityNameSpaceproperty = str[i++].ToString();
                     webPartDefinition[j].lobSystempInstanceroperty = str[i++].ToString();
                     webPartDefinition[j].downloadMethodproperty = str[i++].ToString();
                     webPartDefinition[j].associatedEntityName = str[i++].ToString();                     
                     webPartDefinition[j].providerConnectionPointID = str[i++].ToString();
                     webPartDefinition[j].entityfieldsproperty1 = getBlockProperty();
                     webPartDefinition[j].entityfieldsproperty2 = getBlockProperty();
                     webPartDefinition[j].entityfieldsproperty3 = getBlockProperty();
                     webPartDefinition[j].entityfieldsproperty4 = getBlockProperty();
                     webPartDefinition[j].webpartType = WebpartTypeCodes.BusinessDataRelatedList;
                     webPartDefinition[j].WebPartName = "Show" + webPartDefinition[j].entityNameproperty + "List";
                     webPartDefinition[j].connectionID = "Connection" + (j + 1).ToString();
                     if (webPartDefinition[j].associatedEntityName.CompareTo(webPartDefinition[0].entityNameproperty) == 0)
                         webPartDefinition[j].providerID = Constants.BusinessDataItemBuilder;
                     else
                         webPartDefinition[j].providerID = "Show" + webPartDefinition[j].associatedEntityName + "List";
                     webPartDefinition[j].consumerConnectionPointID = Constants.BDWPRelatedItems;
                     //webPartDefinition[j].providerConnectionPointID = Constants.BDWPItem;
                     webPartDefinition[j].webpartOrder = j;
                     webPartDefinition[j].fullSchema = webPartStandarddefinition[2].schema;
                     j++;
                     webPartDefinition[j] = new WebPartDefinition();
                     webPartDefinition[j].entityNameproperty = webPartDefinition[j - 1].entityNameproperty;
                     webPartDefinition[j].entityNameSpaceproperty = webPartDefinition[j - 1].entityNameSpaceproperty;
                     webPartDefinition[j].lobSystempInstanceroperty = webPartDefinition[j - 1].lobSystempInstanceroperty;
                     webPartDefinition[j].downloadMethodproperty = webPartDefinition[j - 1].downloadMethodproperty;
                     webPartDefinition[j].providerConnectionPointID = Constants.BDWPRow;
                     if (webPartDefinition[j - 1].providerID.CompareTo(Constants.BusinessDataItemBuilder) == 0)
                     {
                         webPartDefinition[j].webpartType = WebpartTypeCodes.RelatedDocumentAction;
                         webPartDefinition[j].fullSchema = webPartStandarddefinition[5].schema;
                     }
                     else
                     {
                         webPartDefinition[j].webpartType = WebpartTypeCodes.RelatedDocumentAction2;
                         webPartDefinition[j].fullSchema = webPartStandarddefinition[6].schema;
                     }
                     webPartDefinition[j].WebPartName = "RelatedDocAction";
                     webPartDefinition[j].connectionID = "Connection" + (j + 1).ToString();
                     webPartDefinition[j].providerID = webPartDefinition[j - 1].WebPartName;
                     webPartDefinition[j].consumerConnectionPointID = Constants.BDWPItem;
                     //webPartDefinition[j].providerConnectionPointID = Constants.BDWPItem;
                     webPartDefinition[j].webpartOrder = j;
                     j++;
                 }
                 else if (webPartTypes.CompareTo(WebpartTypeCodes.BusinessDataList.ToString()) == 0)
                 {
                     webPartDefinition[j].entityNameproperty = str[i++].ToString();
                     webPartDefinition[j].entityNameSpaceproperty = str[i++].ToString();
                     webPartDefinition[j].lobSystempInstanceroperty = str[i++].ToString();
                     webPartDefinition[j].Finderproperty = str[i++].ToString();
                     webPartDefinition[j].associatedEntityName = str[i++].ToString();
                     webPartDefinition[j].entityfieldsproperty1 = getBlockProperty();
                     webPartDefinition[j].entityfieldsproperty2 = getBlockProperty();
                     webPartDefinition[j].entityfieldsproperty3 = getBlockProperty();
                     webPartDefinition[j].entityfieldsproperty4 = getBlockProperty();                     
                     webPartDefinition[j].webpartType = WebpartTypeCodes.BusinessDataRelatedList;
                     webPartDefinition[j].WebPartName = "Show" + webPartDefinition[j].entityNameproperty + "List";
                     webPartDefinition[j].connectionID = "Connection" + (j + 1).ToString();
                     if (webPartDefinition[j].associatedEntityName.CompareTo(webPartDefinition[0].entityNameproperty) == 0)
                         webPartDefinition[j].providerID = Constants.BusinessDataItemBuilder;
                     else
                         webPartDefinition[j].providerID = "Show" + webPartDefinition[j].associatedEntityName + "List";
                     webPartDefinition[j].fullSchema = webPartStandarddefinition[7].schema;
                     webPartDefinition[j].consumerConnectionPointID = Constants.BDWPItem;
                     //webPartDefinition[j].providerConnectionPointID = Constants.BDWPItem;
                     webPartDefinition[j].webpartOrder = j;
                     j++;
                 }
                 else
                 {
                     MessageBox.Show("Item does not exist" + webPartTypes);
                 }


             }

             string[] leftZone, rightzone;
             leftZone = new string[j];
          
            
             bool relatedactionwebpartExists = false;
             for (int k = 0; k < j; k++)
             {
                 leftZone[k] = webPartDefinition[k].WebPartName;               

                 if (webPartDefinition[k].webpartType == WebpartTypeCodes.BusinessDataActions)
                     relatedactionwebpartExists = true;

             }
             // adding duet specific webparts
             webPartDefinition[j] = new WebPartDefinition();
             webPartDefinition[j].WebPartName = "IM Contacts";
             webPartDefinition[j].webpartOrder = j;
             webPartDefinition[j].webpartType = WebpartTypeCodes.Others;
             webPartDefinition[j].fullSchema = webPartStandarddefinition[8].schema;
             j++;

             webPartDefinition[j] = new WebPartDefinition();
             webPartDefinition[j].WebPartName = "Discussion List";
             webPartDefinition[j].webpartOrder = j;
             webPartDefinition[j].webpartType = WebpartTypeCodes.Others;
             webPartDefinition[j].fullSchema = webPartStandarddefinition[9].schema;
             j++;

             // check ISV added related action webpart
             if (relatedactionwebpartExists)
             {
                 rightzone = new string[3];
                 rightzone[0] = "IM Contacts";
                 rightzone[1] = "Discussion List";
                 rightzone[2] = "Related Reports Library";
                 webPartDefinition[j] = new WebPartDefinition();
                 webPartDefinition[j].WebPartName = "Related Reports Library";
                 webPartDefinition[j].webpartType = WebpartTypeCodes.Others;
                 webPartDefinition[j].fullSchema = webPartStandarddefinition[10].schema;
                 webPartDefinition[j].webpartOrder = j;
                 j++;
             }
             else
             {
                 rightzone = new string[2];
                 rightzone[0] = "IM Contacts";
                 rightzone[1] = "Discussion List";                 
             }

             WebPartOrderForm wform = new WebPartOrderForm(leftZone, rightzone);
             wform.ShowDialog();

             string[] userLeftZone, userRightzone;
             userLeftZone = new string[10];
             userRightzone = new string[10];
             userRightzone = wform.rightZone;
             userLeftZone = wform.leftZone;

             for (int k = 0; k < j; k++)
             {
                 for (int l = 0; l < userLeftZone.Length; l++)
                 {
                     if (String.Compare(webPartDefinition[k].WebPartName.ToString(), userLeftZone[l].ToString()) == 0)
                     {
                         webPartDefinition[k].webpartOrder = l + 1;
                         webPartDefinition[k].webpartZone = "Left";
                         break;
                     }
                 }
                 for (int m = 0; m < userRightzone.Length; m++)
                 {
                     if (String.Compare(webPartDefinition[k].WebPartName.ToString(), userRightzone[m].ToString()) == 0)
                     {

                         webPartDefinition[k].webpartOrder = m + 1;
                         webPartDefinition[k].webpartZone = "Right";
                         break;
                     }
                 }
             }

             string newZone = null;
             int zoneOrder=0;
             // generating connection properties and webpart definition
             for (int k = 0; k < j; k++)
             {
                 if (webPartDefinition[k].webpartType != WebpartTypeCodes.Others)
                 {
                     connectionString += "<WebPartConnection ID=" + '"' + webPartDefinition[k].connectionID + '"' + " ConsumerID=" + '"' + webPartDefinition[k].WebPartName + '"' + " ProviderID=" + '"' + webPartDefinition[k].providerID + '"';
                     connectionString += " ConsumerConnectionPointID=" + '"' + webPartDefinition[k].consumerConnectionPointID + '"' + " ProviderConnectionPointID=" + '"' + webPartDefinition[k].providerConnectionPointID + '"' + " />";
                     connectionString += System.Environment.NewLine;

                     if (webPartDefinition[k].webpartType == WebpartTypeCodes.RelatedDocumentAction2)
                     {
                         connectionString += "<WebPartConnection ID=" + '"' + webPartDefinition[k].connectionID + "12" + '"' + " ConsumerID=" + '"' + webPartDefinition[k].WebPartName + "Upload" + '"' + " ProviderID=" + '"' + webPartDefinition[k - 1].providerID + '"';
                         connectionString += " ConsumerConnectionPointID=" + '"' + webPartDefinition[k].consumerConnectionPointID + '"' + " ProviderConnectionPointID=" + '"' + webPartDefinition[k].providerConnectionPointID + '"' + " />";
                         connectionString += System.Environment.NewLine;
                        
                     }

                     
                     string temp = webPartDefinition[k].fullSchema;
                     temp = temp.Replace("$WebPartName$", webPartDefinition[k].WebPartName);
                     temp = temp.Replace("$Zone$", webPartDefinition[k].webpartZone);
                     if (newZone!= null && newZone.CompareTo(webPartDefinition[k].webpartZone) == 0 && zoneOrder <= webPartDefinition[k].webpartOrder)
                         webPartDefinition[k].webpartOrder+=1;
                     temp = temp.Replace("$WebPartOrder$", webPartDefinition[k].webpartOrder.ToString());
                     temp = temp.Replace("$EntityNameproperty$", webPartDefinition[k].entityNameproperty);
                     temp = temp.Replace("$LobSystempInstanceroperty$", webPartDefinition[k].lobSystempInstanceroperty);
                     temp = temp.Replace("$EntityNameSpaceproperty$", webPartDefinition[k].entityNameSpaceproperty);
                     temp = temp.Replace("$Entityfieldsproperty1$", webPartDefinition[k].entityfieldsproperty1);
                     temp = temp.Replace("$Entityfieldsproperty2$", webPartDefinition[k].entityfieldsproperty2);
                     temp = temp.Replace("$Entityfieldsproperty3$", webPartDefinition[k].entityfieldsproperty3);
                     temp = temp.Replace("$Entityfieldsproperty4$", webPartDefinition[k].entityfieldsproperty4);
                     temp = temp.Replace("$DownloadMethodproperty$", webPartDefinition[k].downloadMethodproperty);

                     if (webPartDefinition[k].webpartType == WebpartTypeCodes.RelatedDocumentAction2)
                     {
                         zoneOrder = webPartDefinition[k].webpartOrder;
                         temp = temp.Replace("$WebPartOrder1$", zoneOrder.ToString());
                         zoneOrder++;
                         temp = temp.Replace("$WebPartOrder2$", zoneOrder.ToString());                         
                         temp = temp.Replace("$EntityNameproperty1$", webPartDefinition[2].entityNameproperty);
                         temp = temp.Replace("$LobSystempInstanceroperty1$", webPartDefinition[2].lobSystempInstanceroperty);
                         temp = temp.Replace("$EntityNameSpaceproperty1$", webPartDefinition[2].entityNameSpaceproperty);
                         newZone = webPartDefinition[k].webpartZone;
                     
                      }
                     temp += System.Environment.NewLine;
                     webpartsData += temp;
                 }
                 else
                 {
                     string temp = webPartDefinition[k].fullSchema;
                     temp = temp.Replace("$WebPartName$", webPartDefinition[k].WebPartName);
                     temp = temp.Replace("$Zone$", webPartDefinition[k].webpartZone);
                     temp = temp.Replace("$WebPartOrder$", webPartDefinition[k].webpartOrder.ToString());
                     webpartsData += temp;
                 }

             }
             replacementsDictionary.Add("$webpartsData$", webpartsData);
             replacementsDictionary.Add("$connectionString$", connectionString);

         }

         string getBlockProperty()
         {
             string customProperty = null;

             if (str[i].CompareTo(startBlock) != 0)
             {
                 MessageBox.Show("Not expected string:" + str[i]);
                 return null;
             }

             for (int j = i + 1; j < str.Length; j++)
             {
                 if (str[j].CompareTo(endBlock) == 0)
                 {
                     i = j + 1;
                     break;
                 }
                 customProperty += str[j].ToString() + System.Environment.NewLine;
             }
             return customProperty;
         }
         public bool ShouldAddProjectItem(string filePath)
         {
             return true;
         }

        // Load the standard definition for the webparts
         public void getStandardDefinition()
         {
             int l = 0;
             
             string fileName = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)+@"\WebPartSchemaDefinition.xml";
             String[] str = File.ReadAllLines(fileName);

             string customProperty = null;
             for (int m = 0; m < 11; m++)
             {
                 webPartStandarddefinition[m] = new WebPartStandardDefinition();
                 webPartStandarddefinition[m].webpartType = str[l++];

                 customProperty = null;
                 for (int j = l + 1; j < str.Length; j++)
                 {
                     if (str[j].CompareTo(endBlock) == 0)
                     {
                         l = j + 1;
                         break;
                     }
                     customProperty += str[j].ToString() + System.Environment.NewLine;
                 }
                 webPartStandarddefinition[m].schema = customProperty;
             }
         }

     }
   
    public class WebPartDefinition
    {
        public WebpartTypeCodes webpartType;
        public string WebPartName;
        public string webpartZone;
        public int webpartOrder;
        public string entityNameproperty = null;
        public string entityNameSpaceproperty = null;
        public string lobSystempInstanceroperty;
        public string specificFinderproperty;
        public string downloadMethodproperty;
        public string Finderproperty;
        public string entityfieldsproperty1;
        public string entityfieldsproperty2;
        public string entityfieldsproperty3;
        public string entityfieldsproperty4;
        public string connectionID;
        public string providerID;
        public string consumerConnectionPointID;
        public string providerConnectionPointID;
        public string associatedEntityName;
        public string fullSchema;
        
    }
  

}
